package com.mls.guardian.executor.slave;

import com.mls.guardian.container.SlaveContainer;
import com.mls.guardian.dataobj.FileObj;
import com.mls.guardian.protocol.RemoteBody;
import com.mls.guardian.protocol.RemoteCommand;
import com.mls.guardian.protocol.body.FileInfoBody;
import com.mls.guardian.protocol.body.ServerInfoBody;
import com.mls.guardian.remoting.executor.RemoteExecutor;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by 2014-400 on 2015-11-30.
 */
public class SlaveGetFileInfoExecutor implements RemoteExecutor {
    private static final Logger log = LoggerFactory.getLogger(SlaveGetFileInfoExecutor.class);
    private SlaveContainer container;

    public SlaveGetFileInfoExecutor(SlaveContainer container) {
        this.container = container;
    }

    @Override
    public RemoteBody execute(ChannelHandlerContext ctx, RemoteCommand request) throws Exception {
        FileInfoBody fileInfoBody = (FileInfoBody) request.getRemoteBody();

        List<FileObj> fileObjList = container.getAppController().getFileInfo(fileInfoBody.getProjectName(), fileInfoBody.getModuleName(), fileInfoBody.getParent());
        fileInfoBody.setSuc(true);
        fileInfoBody.setChildren(fileObjList);

        return fileInfoBody;
    }
}